package com.sali.design_pattern.c_factory_method_pattern.lesson_03.service.mode;

import com.sali.design_pattern.c_factory_method_pattern.lesson_03.service.vip.IUserVipService;
import com.sali.design_pattern.c_factory_method_pattern.lesson_03.service.vip.NormalUserService;
import com.sali.design_pattern.c_factory_method_pattern.lesson_03.service.vip.SVIPUserService;
import com.sali.design_pattern.c_factory_method_pattern.lesson_03.service.vip.VIPUserService;

/**
 * @description: 工厂类--开闭原则
 * @author: zhang hang
 * @date: 2022/11/5 10:46.
 * @version: 1.0
 */
public class UserFactoryBean {

    /**
     * description: 通过简单工厂设计模式，完成不同身份的对象获取
     **/
    public static IUserVipService getInstance(Integer vip) {

        IUserVipService userVipService = null;

        // 此处破坏了开闭原则
        if (vip.equals(3L)) {
            // svip用户
            userVipService = new SVIPUserService();
        } else if (vip.equals(2L)) {
            // vip用户
            userVipService = new VIPUserService();
        } else {
            // 普通用户
            userVipService = new NormalUserService();
        }
        return userVipService;
    }

}
